Previous Page

nihilist - 16 / 07 / 2023

safetwitch Setup

In this tutorial we're going to setup a privacy front-end for Twitch.

Initial Setup

First clone the project:


[ nowhere.moe ] [ /dev/pts/1 ] [/srv]
→ git clone https://codeberg.org/dragongoose/safetwitch
Cloning into 'safetwitch'...
remote: Enumerating objects: 985, done.
remote: Counting objects: 100% (985/985), done.
remote: Compressing objects: 100% (540/540), done.
remote: Total 985 (delta 601), reused 685 (delta 409), pack-reused 0
Receiving objects: 100% (985/985), 387.95 KiB | 5.39 MiB/s, done.
Resolving deltas: 100% (601/601), done.
	
[ nowhere.moe ] [ /dev/pts/1 ] [/srv]
→ cd safetwitch

[ nowhere.moe ] [ /dev/pts/1 ] [/srv/safetwitch]
→ cat docker-compose.yml
version: "3.7"
services:
  safetwitch-frontend:
    image: codeberg.org/dragongoose/safetwitch
    ports:
      - "5070:80"
    environment:
      - SAFETWITCH_BACKEND_DOMAIN=api.safetwitch.nowhere.moe
      - SAFETWITCH_INSTANCE_DOMAIN=safetwitch.nowhere.moe
      - SAFETWITCH_HTTPS=true
    restart: always
  safetwitch-backend:
    image: codeberg.org/dragongoose/safetwitch-backend
    ports:
      - "5071:7000"
    environment:
      - PORT=7000
      - URL=https://api.safetwitch.nowhere.moe
    restart: always

[ nowhere.moe ] [ /dev/pts/1 ] [/srv/safetwitch]
→ docker-compose up -d
Creating network "safetwitch_default" with the default driver
Pulling safetwitch-frontend (codeberg.org/dragongoose/safetwitch:latest)...
latest: Pulling from dragongoose/safetwitch
d0de230e4980: Pull complete
b42fa9547f79: Pull complete
aba2ce7a518a: Pull complete
7d78fe4bd2d4: Pull complete
533199e0e5fa: Pull complete
3c324febbea5: Pull complete
389db9210558: Pull complete
cb70d3a168ec: Pull complete
c2aae053f4c3: Pull complete
b5aa6a893904: Pull complete
6ff1a70f50b5: Pull complete
94567324fd2c: Pull complete
363f44553ce3: Pull complete
Digest: sha256:6d6041509f1649be8ee38b87efc0cc87500293d1e41d5f7d7a99841420dbc110
Status: Downloaded newer image for codeberg.org/dragongoose/safetwitch:latest
Pulling safetwitch-backend (codeberg.org/dragongoose/safetwitch-backend:latest)...
latest: Pulling from dragongoose/safetwitch-backend
5119035169e2: Pull complete
5016f2f7d1e0: Pull complete
a642e0bacbdb: Pull complete
Digest: sha256:c2e9e9fe54fc33a4a42086cb9d589e7e9cddb8df516879203da0f2506c3acbf4
Status: Downloaded newer image for codeberg.org/dragongoose/safetwitch-backend:latest
Creating safetwitch-backend  ... done
Creating safetwitch-frontend ... done

[ nowhere.moe ] [ /dev/pts/1 ] [/srv/safetwitch]
→ nmap 127.0.0.1 -p 7100
Starting Nmap 7.93 ( https://nmap.org ) at 2023-07-16 13:17 CEST
Nmap scan report for localhost.localdomain (127.0.0.1)
Host is up (0.000070s latency).

PORT     STATE SERVICE
7100/tcp open  font-service

Nmap done: 1 IP address (1 host up) scanned in 0.11 seconds

[ nowhere.moe ] [ /dev/pts/1 ] [/srv/safetwitch]
→ nmap 127.0.0.1 -p 8280
Starting Nmap 7.93 ( https://nmap.org ) at 2023-07-16 13:21 CEST
Nmap scan report for localhost.localdomain (127.0.0.1)
Host is up (0.000050s latency).

PORT     STATE SERVICE
8280/tcp open  synapse-nhttp

Nmap done: 1 IP address (1 host up) scanned in 0.10 seconds

Next step is to put the service behind a reverse nginx proxy:


[ nowhere.moe ] [ /dev/pts/1 ] [/etc/nginx/sites-available]
→ bash
root@Datura /etc/nginx/sites-available # cat /etc/nginx/sites-available/safetwitch.nowhere.moe.conf

server {
        listen 443 ssl;
        server_name safetwitch.nowhere.moe;

        ssl_certificate /etc/acme/certs/safetwitch.nowhere.moe/safetwitch.nowhere.moe.cer;
    ssl_certificate_key /etc/acme/certs/safetwitch.nowhere.moe/safetwitch.nowhere.moe.key;


   location / {
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_pass http://localhost:5070;
    }

}

root@Datura /etc/nginx/sites-available # cat /etc/nginx/sites-available/api.safetwitch.nowhere.moe.conf
server {
        listen 443 ssl;
        server_name api.safetwitch.nowhere.moe;

        ssl_certificate /etc/acme/certs/api.safetwitch.nowhere.moe/api.safetwitch.nowhere.moe.cer;
    ssl_certificate_key /etc/acme/certs/api.safetwitch.nowhere.moe/api.safetwitch.nowhere.moe.key;

        access_log  off;
    error_log off;


    location / {
        #root /app;
        #index index.html;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_pass http://localhost:5071;
        #try_files $uri $uri/ /index.html;
    }
}

[ nowhere.moe ] [ /dev/pts/1 ] [/srv/safetwitch]
→ nginx -s reload
2023/07/16 13:22:11 [notice] 306635#306635: signal process started
root@Datura /etc/nginx/sites-available # systemctl stop nginx
root@Datura /etc/nginx/sites-available # acme.sh --issue --standalone -d safetwitch.nowhere.moe -d api.safetwitch.nowhere.moe -k 4096
root@Datura /etc/nginx/sites-available # ln -s /etc/nginx/sites-available/safetwitch.nowhere.moe.conf /etc/nginx/sites-enabled/
root@Datura /etc/nginx/sites-available # ln -s /etc/nginx/sites-available/api.safetwitch.nowhere.moe.conf /etc/nginx/sites-enabled/
root@Datura /etc/nginx/sites-available # nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
root@Datura /etc/nginx/sites-available # systemctl restart nginx
	

Then browse to see if your instance is working:

Last step is to contribute to the overall list of instances like so

(Special thanks to Arya from https://projectsegfau.lt for the helping making my instance work.)

Next we're going to make sure it gets automatically updated like so:


[ nowhere.moe ] [ /dev/pts/1 ] [~]
→ crontab -e
@hourly docker-compose -f /srv/safetwitch/docker-compose.yml stop ; git -C /srv/safetwitch/ pull ; docker-compose -f /srv/safetwitch/docker-compose.yml pull ; docker-compose -f /srv/safetwitch/docker-compose.yml up -d


[ nowhere.moe ] [ /dev/pts/1 ] [~]
→ cronitor select

✔ docker-compose -f /srv/safetwitch/docker-compose.yml stop ; git -C /srv/safetwitch/ pull ; docker-compose -f /srv/safetwitch/docker-compose.yml up -d
----► Running command: docker-compose -f /srv/safetwitch/docker-compose.yml stop ; git -C /srv/safetwitch/ pull ; docker-compose -f /srv/safetwitch/docker-compose.yml up -d

Stopping safetwitch_safetwitch-frontend_1 ... done
Stopping safetwitch_safetwitch-backend_1  ... done
From https://codeberg.org/dragongoose/safetwitch
   4d5645f..af00bd5  master     -> origin/master
 * [new tag]         v1.1.3     -> v1.1.3
Updating 4d5645f..af00bd5
Fast-forward
 README.md                           | 127 +-----------------------------------
 src/components/LanguageSwitcher.vue |   4 +-
 src/components/SearchBar.vue        |   2 -
 src/i18n.ts                         |   2 +
 src/locales                         |   2 +-
 5 files changed, 8 insertions(+), 129 deletions(-)
Starting safetwitch-frontend ... done
Starting safetwitch-backend  ... done

----► ✔ Command successful    Elapsed time 12.228s

[ nowhere.moe ] [ /dev/pts/2 ] [~]
→ cronitor select

✔ docker-compose -f /srv/safetwitch/docker-compose.yml stop ; git -C /srv/safetwitch/ pull ; docker-compose -f /srv/safetwitch/docker-compose.yml pull ; docker-compose -f /srv/safetwitch/docker-compose.yml up -d
----► Running command: docker-compose -f /srv/safetwitch/docker-compose.yml stop ; git -C /srv/safetwitch/ pull ; docker-compose -f /srv/safetwitch/docker-compose.yml pull ; docker-compose -f /srv/safetwitch/docker-compose.yml up -d

Stopping safetwitch_safetwitch-frontend_1 ... done
Stopping safetwitch_safetwitch-backend_1  ... done
Already up to date.
Pulling safetwitch-frontend ... done
Pulling safetwitch-backend  ... done
Starting safetwitch_safetwitch-frontend_1 ... done
Starting safetwitch_safetwitch-backend_1  ... done

----► ✔ Command successful    Elapsed time 12.885s

Nihilism

Until there is Nothing left.



Creative Commons Zero: No Rights Reserved

About nihilist

Donate XMR: 8AUYjhQeG3D5aodJDtqG499N5jXXM71gYKD8LgSsFB9BUV1o7muLv3DXHoydRTK4SZaaUBq4EAUqpZHLrX2VZLH71Jrd9k8


Contact: nihilist@contact.nowhere.moe (PGP)